/*
This file is part of Sencha Touch 2.1

Copyright (c) 2011-2013 Sencha Inc

Contact:  http://www.sencha.com/contact

GNU General Public License Usage
This file may be used under the terms of the GNU General Public License version 3.0 as
published by the Free Software Foundation and appearing in the file LICENSE included in the
packaging of this file.

Please review the following information to ensure the GNU General Public License version 3.0
requirements will be met: http://www.gnu.org/copyleft/gpl.html.

If you are unsure which license is appropriate for your use, please contact the sales department
at http://www.sencha.com/contact.

Build date: 2013-02-05 12:25:50 (3ba7c63bea96e5ea776e2bbd67cfb0aa01e43322)
*/
/*
This file is part of Sencha Touch 2.1

Copyright (c) 2011-2013 Sencha Inc

Contact:  http://www.sencha.com/contact

GNU General Public License Usage
This file may be used under the terms of the GNU General Public License version 3.0 as
published by the Free Software Foundation and appearing in the file LICENSE included in the
packaging of this file.

Please review the following information to ensure the GNU General Public License version 3.0
requirements will be met: http://www.gnu.org/copyleft/gpl.html.

If you are unsure which license is appropriate for your use, please contact the sales department
at http://www.sencha.com/contact.

Build date: 2013-02-05 12:25:50 (3ba7c63bea96e5ea776e2bbd67cfb0aa01e43322)
*/
/*
This file is part of Sencha Touch 2.1

Copyright (c) 2011-2013 Sencha Inc

Contact:  http://www.sencha.com/contact

GNU General Public License Usage
This file may be used under the terms of the GNU General Public License version 3.0 as
published by the Free Software Foundation and appearing in the file LICENSE included in the
packaging of this file.

Please review the following information to ensure the GNU General Public License version 3.0
requirements will be met: http://www.gnu.org/copyleft/gpl.html.

If you are unsure which license is appropriate for your use, please contact the sales department
at http://www.sencha.com/contact.

Build date: 2013-02-05 12:25:50 (3ba7c63bea96e5ea776e2bbd67cfb0aa01e43322)
*/
/*
This file is part of Sencha Touch 2.1

Copyright (c) 2011-2013 Sencha Inc

Contact:  http://www.sencha.com/contact

GNU General Public License Usage
This file may be used under the terms of the GNU General Public License version 3.0 as
published by the Free Software Foundation and appearing in the file LICENSE included in the
packaging of this file.

Please review the following information to ensure the GNU General Public License version 3.0
requirements will be met: http://www.gnu.org/copyleft/gpl.html.

If you are unsure which license is appropriate for your use, please contact the sales department
at http://www.sencha.com/contact.

Build date: 2013-02-05 12:25:50 (3ba7c63bea96e5ea776e2bbd67cfb0aa01e43322)
*/
//<debug>
Ext.Loader.setPath({
    'Ext': 'touch/src',
    'HRMobile': 'app',
    'Ext.ux.touch.Rating': 'touch/src/ux/touch/Ext.ux.touch.Rating.js'
});
//</debug>

Ext.application({
    name: 'HRMobile',

    requires: [
        'Ext.MessageBox',
        'Ext.chart.PolarChart',
        'Ext.chart.series.Pie',
        'Ext.chart.interactions.Rotate',
        'Ext.navigation.View',
        'Ext.ux.touch.Rating',
        'Ext.carousel.Carousel',
        'Ext.field.Select',
        'Ext.Label',
        'Ext.chart.axis.Numeric',
        'Ext.chart.axis.Category',
        'Ext.chart.series.Bar',
        'Ext.plugin.ListPaging',
        'Ext.plugin.PullRefresh',
        'Ext.data.proxy.JsonP',
        'Ext.field.Radio',
        'Ext.field.Checkbox',
        'Ext.field.DatePicker'
    ],

    views: ['LoginForm',
            'EmployeeListForm',
            'Main',
            'EmployeeDetailForm',
            'LeftNavigator',
            'employeeDetails.PersonalDetailsForm',
            'employeeDetails.ContactDetailsForm',
            'employeeDetails.EmergencyContactsForm',
            'employeeDetails.DependentsForm',
            'employeeDetails.JobsForm',
            'employeeDetails.SalariesForm',
            'employeeDetails.SupervisorsForm',
            'employeeDetails.SubordinatesForm',
            'employeeDetails.ExperienceForm',
            'employeeDetails.EducationForm',
            'employeeDetails.SkillForm',
            'employeeDetails.LanguageForm',
            'employeeDetails.LicenseForm',
            'LeaveRequestListForm',
            'chart.EmpGenderChart',
            'chart.EmpAgeChart',
            'chart.StructureChart',
            'chart.LeaveReasonChart',
            'chart.LeaveByMonthChart',
            'chart.LeaveByDepartmentChart',
            'About',
            'SurveyListForm',
            'YourLeaveRequestListForm'],
    
    controllers: ['LoginController',
                  'EmployeeController',
                  'LeaveController',
                  'HomeController',
                  'SurveyController'],
    icon: {
        '57': 'resources/icons/loginLogo_57x57.png.png',
        '72': 'resources/icons/loginLogo_57x57.png.png',
        '114': 'resources/icons/loginLogo.png',
        '144': 'resources/icons/loginLogo.png'
    },

    isIconPrecomposed: true,

//    startupImage: {
//        '320x460': 'resources/startup/320x460.jpg',
//        '640x920': 'resources/startup/640x920.png',
//        '768x1004': 'resources/startup/768x1004.png',
//        '748x1024': 'resources/startup/748x1024.png',
//        '1536x2008': 'resources/startup/1536x2008.png',
//        '1496x2048': 'resources/startup/1496x2048.png'
//    },

    launch: function() {
        // Destroy the #appLoadingIndicator element
        Ext.fly('appLoadingIndicator').destroy();
        // Initialize the main view
        if (localStorage.userId == undefined){
        	Ext.Viewport.add(Ext.create('HRMobile.view.LoginForm'));
        }
        else {
        	Ext.Viewport.setActiveItem(Ext.create('HRMobile.view.Main'));
    		Ext.getCmp('lblWelcome').setHtml('<b>Welcome '+ localStorage.userShortName+'!</b>');

    		var store = Ext.getStore('LeaveRequestStore');
    	 	store.getProxy().setExtraParam('sup_number',localStorage.userId);
    	 	store.load();
    	 	
    	 	var yourLeaveStore = Ext.getStore('YourLeaveRequestStore');
    	 	yourLeaveStore.getProxy().setExtraParam('userId',localStorage.userId);
    	 	yourLeaveStore.load();
    	 	
    	 	var surveyStore = Ext.getStore('SurveyStore');
    	 	surveyStore.getProxy().setExtraParam('userSubUnitId',localStorage.userSubUnitId);
    	 	surveyStore.getProxy().setExtraParam('userId',localStorage.userIdSurvey);
    	 	surveyStore.load();
    	 	
    	 	var store = Ext.getStore('MySupervisorStore');
    	 	store.getProxy().setExtraParam('emp_number',localStorage.userId);
    	 	store.load();
    	 	if (localStorage.canViewEmployeeList == 'false')
    	 		Ext.getCmp('main').getTabBar().items.getAt(1).hide();
    	 	if (localStorage.canViewChartResource == 'false'){
    	 		Ext.getCmp('crsHomePanel').removeInnerAt(0);
    	 		Ext.getCmp('crsHomePanel').removeInnerAt(0);
    	 		Ext.getCmp('crsHomePanel').removeInnerAt(0);
    	 		Ext.getCmp('slfReport').setOptions({
					text : 'Leave taken by reason',
					value : 0
				},
				{
					text : 'Leave taken by month',
					value : 1
				},
				{
					text : 'Leave taken by subunit',
					value : 2
				});
    	 	}
    	 	if (localStorage.canViewChartLeave == 'false'){
    	 		if (localStorage.canViewChartResource == 'false'){
        	 		Ext.getCmp('crsHomePanel').removeInnerAt(0);
        	 		Ext.getCmp('crsHomePanel').removeInnerAt(0);
        	 		Ext.getCmp('crsHomePanel').removeInnerAt(0);
        	 		Ext.getCmp('slfReport').setOptions({text:'', value:0});
        	 		Ext.getCmp('slfReport').setDisabled(true);
        	 	}
    	 		else {
        	 		Ext.getCmp('crsHomePanel').removeInnerAt(3);
        	 		Ext.getCmp('crsHomePanel').removeInnerAt(3);
        	 		Ext.getCmp('crsHomePanel').removeInnerAt(3);
        	 		Ext.getCmp('slfReport').setOptions({
						text : 'Employee by age',
						value : 0
					},
					{
						text : 'Employee by gender',
						value : 1
					},
					{
						text : 'Structure distribution',
						value : 2
					});
    	 		}
	 		}
    		
        }
        
    },

    onUpdated: function() {
        Ext.Msg.confirm(
            "Application Update",
            "This application has just successfully been updated to the latest version. Reload now?",
            function(buttonId) {
                if (buttonId === 'yes') {
                    window.location.reload();
                }
            }
        );
    }
});
